﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Model
{   
    [Serializable]
    public sealed class WhatIfProject
    {
        private List<HazopTeam> _phaTeamList = new List<HazopTeam>();
        List<string> _psiList = new List<string>();
        List<PID> _pidList = new List<PID>();
        private NewProjectDetails _projectDetails = new NewProjectDetails();
        private List<WhatIfWorkNode> _whatIfNodeList = new List<WhatIfWorkNode>();
        private RiskMatrix _riskMatrix = new RiskMatrix();
        private static WhatIfProject _Project = null;
        private static object _syncObj = new object();
        
        private WhatIfProject(){}
        public static WhatIfProject WhatIfProjectInstance{
            get{
                if (_Project == null)
                {
                    lock (_syncObj){
                        if (_Project == null)
                        {
                            _Project = new WhatIfProject();
                        }
                    }
                }
                return _Project;
            }
        }

        public int GetTotalAdviceCount()
        {
            int count = 0;
            foreach (WhatIfWorkNode node in _whatIfNodeList)
            {
                foreach (WhatIfWorkNodeItem item in node.WhatIfWorkNodeItemList)
                {
                    if (item.Advice != null)
                    {
                        count++;
                    }
                }
            }
            return count;
        }

        public List<WhatIfWorkNodeItem> GetAdviceWorkNodeItem()
        {
            List<WhatIfWorkNodeItem> res = new List<WhatIfWorkNodeItem>();
            foreach (WhatIfWorkNode node in _whatIfNodeList)
            {
                foreach (WhatIfWorkNodeItem item in node.WhatIfWorkNodeItemList)
                {
                    if (item.Advice != null)
                    {
                        res.Add(item);
                    }
                }
            }
            return res;
        }

        public List<HazopTeam> PhaTeamList{
            get { return _phaTeamList; }
            set { _phaTeamList = value; }
        }

        public List<string> PsiList{
            get { return _psiList; }
            set { _psiList = value; }
        }

        public List<PID> PidList{
            get { return _pidList; }
            set { _pidList = value; }
        }

        public NewProjectDetails ProjectDetails{
            get { return _projectDetails; }
            set { _projectDetails = value; }
        }

        public List<WhatIfWorkNode> WhatIfNodeList{
            get { return _whatIfNodeList; }
            set { _whatIfNodeList = value; }
        }

        public RiskMatrix RiskMatrix{
            get { return _riskMatrix; }
            set { _riskMatrix = value; }
        }

        public static WhatIfProject Project{
            get { return _Project; }
            set { _Project = value; }
        }
    }
}
